package com.silence.ByteDance;


import java.util.ArrayList;
import java.util.List;

public class easy_32 {
    public static String solution(String plates) {
        // Please write your code here
        String[] arr = plates.split(" ");
        List<Integer> list = new ArrayList<>();
        for (String s : arr) {
            list.add(Integer.valueOf(s));
        }
        List<Integer> ls = new ArrayList<>();
        StringBuffer res = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            if(i==0){
                ls.add(list.get(0));
            }else{
                if(list.get(i).equals( ls.get(ls.size()-1) +1)){
                    ls.add(list.get(i));
                }else{
                    if(ls.size()>2){
                        res.append(ls.get(0)).append("-").append(ls.get(ls.size()-1));
                    }else if(ls.size()>1){
                        res.append(ls.get(0)).append(",").append(ls.get(1));
                    }else {
                        res.append(ls.get(0));
                    }
                    ls = new ArrayList<>();
                    ls.add(list.get(i));
                    res.append(",");
                }
            }
        }
        if(ls.size()>2){
            res.append(ls.get(0)).append("-").append(ls.get(ls.size()-1));
        }else if(ls.size()>1){
            res.append(ls.get(0)).append(",").append(ls.get(1));
        }else {
            res.append(ls.get(0));
        }
        return res.toString();
    }

    public static void main(String[] args) {
        //  You can add more test cases here
        System.out.println(solution("-3 -2 -1 2 10 15 16 18 19 20").equals("-3--1,2,10,15,16,18-20"));
        System.out.println(solution("-6 -3 -2 -1 0 1 3 4 5 7 8 9 10 11 14 15 17 18 19 20").equals("-6,-3-1,3-5,7-11,14,15,17-20"));
        System.out.println(solution("1 2 7 8 9 10 11 19").equals("1,2,7-11,19"));
        System.out.println(solution("1 2 3 4 5 6 "));
        System.out.println(solution("1 3 5 7 9"));
        System.out.println(solution("1 2 4 5 7 8"));
    }
}
